/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($http,$q,httpservice) {
    var newsService = {};


    //查询动态消息
    newsService.queryMessage = function (sendUserId,receiveuserid,itemid,pageNum,pageSize) {
        var  params = {"senduserid":sendUserId,"receiveuserid":receiveuserid,"itemid":itemid,"pageNum":pageNum,"pageSize":pageSize};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.DynamicMessageUrl,
            data:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**接受消息*/
    newsService.acceptOrRejectMsg = function (status,id) {
        var  params ={"status":status,"id":id};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.receiveMessageUrl,
            data:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**拒绝消息*/
    newsService.RefuseMsg = function (status,id) {
        var  params ={"status":status,"id":id};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.receiveMessageUrl,
            data:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    /**系统消息*/
    newsService.SystemMsg = function (userid,pageNum,pageSize) {
      /*  {"userid":"37","pageNum":"0","pageSize":"10"}*/
        var  params ={"userid":userid,"pageNum":pageNum,"pageSize":pageSize};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.SystemMessageUrl,
            data:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    return newsService;
};
